// @coding: utf8
// @author: enic

package network

import (
	"sync"
)

// 连接ID分配器
type ConnIDMgr struct {
	//activeIDSet
	nextId uint64
	lock   sync.Mutex
}

func NewConnIdMgr() *ConnIDMgr {
	return &ConnIDMgr{
		nextId: 1,
	}
}

func (mgr *ConnIDMgr) GenId() uint64 {
	new_id := mgr.nextId
	mgr.lock.Lock()
	mgr.nextId++
	if 0 == mgr.nextId {
		mgr.nextId = 1
	}
	mgr.lock.Unlock()

	return new_id
}
